package com.lagou.stage04;

/**
 * 火车买票案例 (两种实现方式) : 共100张票,三个线程一起卖票,不允许出现出现负票和多卖的现象  (描述设置锁的时候要注意的事项:(Thread 和Runnable)
 * 参考答案
 * Thread方式实现
 * Runnable方式实现
 * */

public class TicketTest {
    public static void main(String[] args) {
        //TicketStore ticketStore = new TicketStore();
        TicketStore ticketStore = new TicketStore(20);
        // 1.Runnable方式实现
        System.out.println("Runnable接口实现类方式实现买火车票");
        BuyTicketRunnable btr = new BuyTicketRunnable(ticketStore);
        ProductTicketRunnable ptr = new ProductTicketRunnable(ticketStore, 10);
        Thread btrthread1 = new Thread(btr);
        Thread btrthread2= new Thread(btr);
        Thread btrthread3 = new Thread(btr);
        //Thread ptrthread = new Thread(ptr);
        //ptrthread.start();
        btrthread1.start();
        btrthread2.start();
        btrthread3.start();
        System.out.println("--------------------------");

        // 2. Thread方式实现
        System.out.println("Thread继承类方式实现买火车票");
        Thread btthread1 = new BuyTicketTread(ticketStore);
        Thread btthread2 = new BuyTicketTread(ticketStore);
        Thread btthread3 = new BuyTicketTread(ticketStore);
        //Thread ptthread = new ProductTicketThread(ticketStore, 10);
        //btthread1.start();
        //btthread2.start();
        //btthread3.start();
        //ptthread.start();
    }
}
